package cn.sfrog.project.biz.admin.pay;

import cn.sfrog.project.biz.admin.enums.PayMethodEnum;
import cn.sfrog.project.biz.admin.utils.bean.BeanContext;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.Map;

/**
 * 支付工厂
 */
public abstract class PayFactory {
    /**
     * 工厂方法
     * @param payMethodEnum
     * @return
     */
    public static PayFactory getPayService(PayMethodEnum payMethodEnum){
        return BeanContext.getBean(payMethodEnum.getPayClass());
    }

    /**
     * 为前端构造支付参数
     * @return 参数信息
     */
    public abstract String buildPayParams(String tradeSn, BigDecimal price);

    /**
     * 回调处理
     */
    public abstract Map<String,Object> callback(HttpServletRequest request, HttpServletResponse response);

    /**
     * 查询支付状态
     */
    public abstract boolean queryPayStatus(String sn) throws Exception;

    /**
     * 关单
     * @param sn 支付单号
     * @throws Exception 关单异常
     */
    public abstract void closeOrder(String sn) throws Exception;



//    public static BizPayment preparePaymentInfo(Long orderId, BigDecimal price, PayMethodEnum payMethod, OrderTypeEnum orderType){
//        BizPayment bizPayment = new BizPayment();
//        bizPayment.setSn(OrderGenUtils.generateOrderNo());
//        bizPayment.setOrderId(orderId);
//        bizPayment.setUserId(SecurityUtils.getUserId());
//        bizPayment.setAmount(price);
//        bizPayment.setIsPaid(0);
//        bizPayment.setPayType(payMethod.getValue());
//        bizPayment.setCreateTime(new Date());
//        bizPayment.setUpdateTime(new Date());
//        bizPayment.setOrderType(orderType.getValue());
//        return bizPayment;
//    }


}
